<template>
  <div class="time-box">
    <div class="time-l">{{ date1 }}</div>
    <div class="time-r">
      <p>星期{{ week }}</p>
      <p>{{ date2 }}</p>
    </div>
  </div>
</template>

<script>
/**
 * 时间
 * @author 朱琦
 * @date   时间：2022/11/19
 */
export default {
  data() {
    return {
      date1: null,
      date2: null,
      week: null,
      timer: null
    }
  },
  computed: {},
  created() {},
  mounted() {
    this.timer = setInterval(() => {
      this.date1 = this.$dayjs().format('HH:mm:ss')
      this.date2 = this.$dayjs().format('YYYY-MM-DD')
      this.week = this.getWeek(this.$dayjs().day())
    }, 1000)
  },
  methods: {
    getWeek(days) {
      const arr = ['日', '一', '二', '三', '四', '五', '六']
      return arr[days]
    }
  },
  beforeUnmount() {
    clearInterval(this.timer) // 在Vue实例销毁前，清除我们的定时器
  },
  components: {}
}
</script>

<style scoped lang="less">
.time-box {
  display: flex;
  align-items: center;
  margin-left: 20px;
  .time-l {
    font-family: 'digital-7';
    font-size: 36px;
    width: 130px;
    white-space: nowrap;
  }
  .time-r {
    // margin-left: 5px;
    font-size: 12px;
    line-height: 16px;
    p {
      margin: 0;
    }
  }
}
</style>
